/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui;

import java.awt.BorderLayout;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.filechooser.FileNameExtensionFilter;
import javax.swing.table.DefaultTableModel;


import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;

import org.apache.poi.ss.usermodel.WorkbookFactory;
import printadwardpaper.PrintObject;

/**
 *
 * @author THANH
 */
public class MainControl extends javax.swing.JFrame {

    /**
     * Creates new form MainControl
     */
    private File mFileExcel;
    private JFrame frame1;
    private Connection con;
    private boolean isLoadData;
    private ArrayList<PrintObject> listDataToPrint;
    private int currentSttObject;

    public MainControl() {
        initComponents();
        initValue();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnBrowseExcelFile = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        tfPathExcel = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        tfSoHoSoValue = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        tfSoHoSoIndex = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        tfClassValue = new javax.swing.JTextField();
        tfClassIndex = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        tfNameValue = new javax.swing.JTextField();
        tfNameIndexExcel = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        tfAwardsIndex = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        tfSoCapValue = new javax.swing.JTextField();
        tfSoCapIndex = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        tfSoQDValue = new javax.swing.JTextField();
        tfSoQDIndex = new javax.swing.JTextField();
        tfPreAwards = new javax.swing.JTextField();
        tfAwardsValue = new javax.swing.JTextField();
        tfNextAwards = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        tfDonViValue = new javax.swing.JTextField();
        tfDonViIndex = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        tfPhu1Value = new javax.swing.JTextField();
        tfPhu1Index = new javax.swing.JTextField();
        jLabel12 = new javax.swing.JLabel();
        tfPhu2Value = new javax.swing.JTextField();
        tfPhu2Index = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        btnLoadingData = new javax.swing.JButton();
        pnInforLoadData = new javax.swing.JPanel();
        jLabel8 = new javax.swing.JLabel();
        tfCurrentRecord = new javax.swing.JTextField();
        lbTotalRecord = new javax.swing.JLabel();
        btnPreviousRecord = new javax.swing.JButton();
        btnGoHere = new javax.swing.JButton();
        btnNextRecord = new javax.swing.JButton();
        btnPrint = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        tfDatabaseLink = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnBrowseExcelFile.setText("Browse");
        btnBrowseExcelFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBrowseExcelFileActionPerformed(evt);
            }
        });

        jLabel1.setText("Excel path: ");

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Patern", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 10))); // NOI18N
        jPanel1.setToolTipText("");

        tfSoHoSoValue.setToolTipText("Số lưu hồ sơ");

        jLabel2.setText("Số lưu hồ sơ:");

        tfSoHoSoIndex.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tfSoHoSoIndex.setText("C3");

        jLabel3.setText("Lớp:");

        tfClassIndex.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tfClassIndex.setText("G11");

        jLabel4.setText("Tên :");

        tfNameValue.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfNameValueActionPerformed(evt);
            }
        });

        tfNameIndexExcel.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tfNameIndexExcel.setText("G9");

        jLabel5.setText("Danh hiệu:");

        tfAwardsIndex.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tfAwardsIndex.setText("E15");
        tfAwardsIndex.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfAwardsIndexActionPerformed(evt);
            }
        });

        jLabel6.setText("Vào số cấp:");

        tfSoCapIndex.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tfSoCapIndex.setText("F21");

        jLabel7.setText("Kèm theo: ");

        tfSoQDIndex.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tfSoQDIndex.setText("F22");
        tfSoQDIndex.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfSoQDIndexActionPerformed(evt);
            }
        });

        tfPreAwards.setText("Đạt danh hiệu");

        tfNextAwards.setText("trong năm học 2013-2014");

        jLabel10.setText("Đơn vị:");

        tfDonViIndex.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tfDonViIndex.setText("G13");
        tfDonViIndex.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfDonViIndexActionPerformed(evt);
            }
        });

        jLabel11.setText("Phụ 1:");

        tfPhu1Index.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tfPhu1Index.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfPhu1IndexActionPerformed(evt);
            }
        });

        jLabel12.setText("Phụ 2:");

        tfPhu2Index.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        tfPhu2Index.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tfPhu2IndexActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4)
                            .addComponent(jLabel6)
                            .addComponent(jLabel7)
                            .addComponent(jLabel5))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(tfNextAwards, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
                                    .addComponent(tfAwardsValue)
                                    .addComponent(tfSoHoSoValue)
                                    .addComponent(tfClassValue)
                                    .addComponent(tfNameValue)
                                    .addComponent(tfPreAwards)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(tfPhu2Value, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
                                    .addComponent(tfPhu1Value)
                                    .addComponent(tfDonViValue)
                                    .addComponent(tfSoCapValue)
                                    .addComponent(tfSoQDValue))))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(10, 10, 10)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(tfNameIndexExcel, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(tfClassIndex, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 42, Short.MAX_VALUE)
                                    .addComponent(tfSoHoSoIndex, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(tfAwardsIndex, javax.swing.GroupLayout.Alignment.TRAILING)))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(tfSoCapIndex, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfSoQDIndex, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfDonViIndex, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfPhu1Index, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(tfPhu2Index, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addComponent(jLabel10)
                    .addComponent(jLabel11)
                    .addComponent(jLabel12))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(jLabel2))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(tfSoHoSoValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(tfSoHoSoIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(tfClassValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfClassIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(tfNameValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfNameIndexExcel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(tfAwardsIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfPreAwards, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tfAwardsValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tfNextAwards, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel6)
                    .addComponent(tfSoCapValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfSoCapIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(tfSoQDValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfSoQDIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(tfDonViValue, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfDonViIndex, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(tfPhu1Value, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfPhu1Index, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel12)
                    .addComponent(tfPhu2Value, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(tfPhu2Index, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(29, Short.MAX_VALUE))
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Load data", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 1, 10))); // NOI18N

        btnLoadingData.setText("Load Data");
        btnLoadingData.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLoadingDataActionPerformed(evt);
            }
        });

        jLabel8.setText("STT:");

        lbTotalRecord.setText("/123");

        btnPreviousRecord.setText("Trước");
        btnPreviousRecord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPreviousRecordActionPerformed(evt);
            }
        });

        btnGoHere.setText("Tới");
        btnGoHere.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGoHereActionPerformed(evt);
            }
        });

        btnNextRecord.setText("Sau");
        btnNextRecord.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnNextRecordActionPerformed(evt);
            }
        });

        btnPrint.setText("In tất cả");
        btnPrint.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnPrintActionPerformed(evt);
            }
        });

        jButton5.setText("In thông tin hiện tại");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("In với thông tin chỉnh sửa");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout pnInforLoadDataLayout = new javax.swing.GroupLayout(pnInforLoadData);
        pnInforLoadData.setLayout(pnInforLoadDataLayout);
        pnInforLoadDataLayout.setHorizontalGroup(
            pnInforLoadDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnInforLoadDataLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnInforLoadDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(pnInforLoadDataLayout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tfCurrentRecord, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lbTotalRecord, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(btnPrint, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(pnInforLoadDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnInforLoadDataLayout.createSequentialGroup()
                        .addComponent(btnPreviousRecord, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnGoHere, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnNextRecord, javax.swing.GroupLayout.PREFERRED_SIZE, 61, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnInforLoadDataLayout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(jButton6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton5, javax.swing.GroupLayout.PREFERRED_SIZE, 127, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        pnInforLoadDataLayout.setVerticalGroup(
            pnInforLoadDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnInforLoadDataLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnInforLoadDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(tfCurrentRecord, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lbTotalRecord)
                    .addComponent(btnPreviousRecord)
                    .addComponent(btnGoHere)
                    .addComponent(btnNextRecord))
                .addGap(18, 18, 18)
                .addGroup(pnInforLoadDataLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(btnPrint, javax.swing.GroupLayout.DEFAULT_SIZE, 46, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(btnLoadingData)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(pnInforLoadData, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(btnLoadingData, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addComponent(pnInforLoadData, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );

        jLabel9.setText("Tên DB:");

        tfDatabaseLink.setText("//D://test.db");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tfDatabaseLink)
                            .addComponent(tfPathExcel))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnBrowseExcelFile)
                        .addGap(30, 30, 30))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addContainerGap())))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnBrowseExcelFile)
                    .addComponent(jLabel1)
                    .addComponent(tfPathExcel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(tfDatabaseLink, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(52, 52, 52))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnPrintActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPrintActionPerformed
        try {
            for (Iterator<PrintObject> it = listDataToPrint.iterator(); it.hasNext();) {

                PrintObject printObject = it.next();
                updateValueToLayout(printObject);
                readAndRewriteValueInExcel(printObject);
                printFile(mFileExcel);

            }
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainControl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MainControl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidFormatException ex) {
            Logger.getLogger(MainControl.class.getName()).log(Level.SEVERE, null, ex);
        }



    }//GEN-LAST:event_btnPrintActionPerformed

    private void btnBrowseExcelFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBrowseExcelFileActionPerformed

        JFileChooser chooser = new JFileChooser();
        chooser.setFileFilter(new FileNameExtensionFilter("Excel", "xls"));
        int retVal = chooser.showOpenDialog(null);
        if (retVal == JFileChooser.APPROVE_OPTION) {
            mFileExcel = chooser.getSelectedFile();

            //set value to edittext
            tfPathExcel.setText(mFileExcel.getPath());
        }

    }//GEN-LAST:event_btnBrowseExcelFileActionPerformed

    private void tfNameValueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfNameValueActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfNameValueActionPerformed

    private void tfAwardsIndexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfAwardsIndexActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfAwardsIndexActionPerformed

    private void tfSoQDIndexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfSoQDIndexActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfSoQDIndexActionPerformed

    private void btnLoadingDataActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLoadingDataActionPerformed

        try {
            Class.forName("org.sqlite.JDBC");
            con = DriverManager.getConnection("jdbc:sqlite:"+tfDatabaseLink.getText().toString());
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(MainControl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(MainControl.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        try {

            loadingDataToList();
            if (listDataToPrint.size() > 0) {
                updateViewAfterLoading();
                updateStatusInformation();
                updateValueToLayout(listDataToPrint.get(currentSttObject));
            }

        } catch (SQLException ex) {
            Logger.getLogger(MainControl.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btnLoadingDataActionPerformed

    private void btnPreviousRecordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnPreviousRecordActionPerformed
        if (currentSttObject > 0) {
            currentSttObject--;
            updateStatusInformation();
            updateValueToLayout(listDataToPrint.get(currentSttObject));
        }
    }//GEN-LAST:event_btnPreviousRecordActionPerformed

    private void btnNextRecordActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnNextRecordActionPerformed
        if (currentSttObject < listDataToPrint.size() - 1) {
            currentSttObject++;
            updateStatusInformation();
            updateValueToLayout(listDataToPrint.get(currentSttObject));
        }
    }//GEN-LAST:event_btnNextRecordActionPerformed

    private void btnGoHereActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGoHereActionPerformed
        int currentType = Integer.parseInt(tfCurrentRecord.getText().toString().trim());
        if (currentType <= listDataToPrint.size() && currentType >= 1) {
            currentSttObject = currentType - 1;
            updateValueToLayout(listDataToPrint.get(currentSttObject));
        }
    }//GEN-LAST:event_btnGoHereActionPerformed

    private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
        try {
            readAndRewriteValueInExcel(listDataToPrint.get(currentSttObject));
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainControl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MainControl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidFormatException ex) {
            Logger.getLogger(MainControl.class.getName()).log(Level.SEVERE, null, ex);
        }
        printFile(mFileExcel);
    }//GEN-LAST:event_jButton5ActionPerformed

    private void tfDonViIndexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfDonViIndexActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfDonViIndexActionPerformed

    private void tfPhu1IndexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfPhu1IndexActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfPhu1IndexActionPerformed

    private void tfPhu2IndexActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tfPhu2IndexActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tfPhu2IndexActionPerformed

    private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
        PrintObject printObject = new PrintObject(tfNameValue.getText().toString(),
                tfClassValue.getText().toString(),
                tfAwardsValue.getText().toString(),
                tfSoHoSoValue.getText().toString(), 
                tfSoCapValue.getText().toString(), 
                tfSoQDValue.getText().toString(), 
                tfDonViValue.getText().toString(), 
                tfPhu1Value.getText().toString(), 
                tfPhu2Value.getText().toString());
        try {
            readAndRewriteValueInExcel(printObject);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(MainControl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(MainControl.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidFormatException ex) {
            Logger.getLogger(MainControl.class.getName()).log(Level.SEVERE, null, ex);
        }
                printFile(mFileExcel);
    }//GEN-LAST:event_jButton6ActionPerformed

    public void showTableData() {

        frame1 = new JFrame("Database Search Result");
        frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame1.setLayout(new BorderLayout());
//TableModel tm = new TableModel();
        String[] columnNames = {"Id", "Name", "Class", "Awards"};
        DefaultTableModel model = new DefaultTableModel();
        model.setColumnIdentifiers(columnNames);
        //DefaultTableModel model = new DefaultTableModel(tm.getData1(), tm.getColumnNames());
        //table = new JTable(model);
        JTable table = new JTable();
        table.setModel(model);
        table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
        table.setFillsViewportHeight(true);
        JScrollPane scroll = new JScrollPane(table);
        scroll.setHorizontalScrollBarPolicy(
                JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scroll.setVerticalScrollBarPolicy(
                JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);

//String textvalue = textbox.getText();
        int id = 1;
        String name = "";
        String className = "";
        String awards = "";

        try {
            //pst = con.prepareStatement("select * from emp where UNAME='" + from + "'");
            PreparedStatement pst = con.prepareStatement("select * from Table1");
            ResultSet rs = pst.executeQuery();
            int i = 0;
            while (rs.next()) {
                id = rs.getInt("Id");
                name = rs.getString("Name");
                className = rs.getString("Class");
                awards = rs.getString("Awards");
                model.addRow(new Object[]{id, name, className, awards});
                i++;
            }
            if (i < 1) {
                JOptionPane.showMessageDialog(null, "No Record Found", "Error", JOptionPane.ERROR_MESSAGE);
            }
//            if (i == 1) {
//                System.out.println(i + " Record Found");
//            } else {
//                System.out.println(i + " Records Found");
//            }
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
        frame1.add(scroll);
        frame1.setVisible(true);
        frame1.setSize(400, 300);
    }

    private void printFile(File file) {
        try {
            String vbs = "Dim AppExcel\r\n"
                    + "Set AppExcel = CreateObject(\"Excel.application\")\r\n"
                    + "AppExcel.Workbooks.Open(\"" + file.getPath() + "\")\r\n"
                    + "appExcel.ActiveWindow.SelectedSheets.PrintOut\r\n"
                    + "Appexcel.Quit\r\n"
                    + "Set appExcel = Nothing";
            File vbScript = File.createTempFile("vbScript", ".vbs");
            vbScript.deleteOnExit();
            FileWriter fw = new java.io.FileWriter(vbScript);
            fw.write(vbs);
            fw.close();
            System.out.println("Start process");
            Process p = Runtime.getRuntime().exec("cscript //NoLogo " + vbScript.getPath());
            System.out.println("waitfor start");
            p.waitFor();
            System.out.println("waitfor complete");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainControl.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainControl.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainControl.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainControl.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainControl().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBrowseExcelFile;
    private javax.swing.JButton btnGoHere;
    private javax.swing.JButton btnLoadingData;
    private javax.swing.JButton btnNextRecord;
    private javax.swing.JButton btnPreviousRecord;
    private javax.swing.JButton btnPrint;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JLabel lbTotalRecord;
    private javax.swing.JPanel pnInforLoadData;
    private javax.swing.JTextField tfAwardsIndex;
    private javax.swing.JTextField tfAwardsValue;
    private javax.swing.JTextField tfClassIndex;
    private javax.swing.JTextField tfClassValue;
    private javax.swing.JTextField tfCurrentRecord;
    private javax.swing.JTextField tfDatabaseLink;
    private javax.swing.JTextField tfDonViIndex;
    private javax.swing.JTextField tfDonViValue;
    private javax.swing.JTextField tfNameIndexExcel;
    private javax.swing.JTextField tfNameValue;
    private javax.swing.JTextField tfNextAwards;
    private javax.swing.JTextField tfPathExcel;
    private javax.swing.JTextField tfPhu1Index;
    private javax.swing.JTextField tfPhu1Value;
    private javax.swing.JTextField tfPhu2Index;
    private javax.swing.JTextField tfPhu2Value;
    private javax.swing.JTextField tfPreAwards;
    private javax.swing.JTextField tfSoCapIndex;
    private javax.swing.JTextField tfSoCapValue;
    private javax.swing.JTextField tfSoHoSoIndex;
    private javax.swing.JTextField tfSoHoSoValue;
    private javax.swing.JTextField tfSoQDIndex;
    private javax.swing.JTextField tfSoQDValue;
    // End of variables declaration//GEN-END:variables

    private void readAndRewriteValueInExcel(PrintObject record) throws FileNotFoundException, IOException, InvalidFormatException {
        InputStream inp = new FileInputStream(mFileExcel.getPath());
        //InputStream inp = new FileInputStream("workbook.xlsx");

        Workbook wb = WorkbookFactory.create(inp);
        Sheet sheet = wb.getSheetAt(0);

        //value name

        Cell cell = getCellFromIndex(sheet, tfNameIndexExcel.getText().toString());
        updateCellValue(cell, record.getHoTen());


        //value Class
        cell = getCellFromIndex(sheet, tfClassIndex.getText().toString());
        updateCellValue(cell, record.getLop());

        //value awards

        cell = getCellFromIndex(sheet, tfAwardsIndex.getText().toString());
        updateCellValue(cell, tfPreAwards.getText().toString() + " " + record.getDanhHieu() + " " + tfNextAwards.getText().toString());

        //value SoHoSo
        cell = getCellFromIndex(sheet, tfSoHoSoIndex.getText().toString());
        updateCellValue(cell, record.getSoHoSo());

        //value SoCap
        cell = getCellFromIndex(sheet, tfSoCapIndex.getText().toString());
        updateCellValue(cell, record.getSoCap());

        //value SoQD
        cell = getCellFromIndex(sheet, tfSoQDIndex.getText().toString());
        updateCellValue(cell, record.getSoQD());
        
        //value DonVi
        cell = getCellFromIndex(sheet, tfDonViIndex.getText().toString());
        updateCellValue(cell, record.getDonVi());
        
        //value Phu1
        cell = getCellFromIndex(sheet, tfPhu1Index.getText().toString());
        updateCellValue(cell, record.getPhu1());
        
        //Value Phu 2
        cell = getCellFromIndex(sheet, tfPhu2Index.getText().toString());
        updateCellValue(cell, record.getPhu2());

        // Write the output to a file
        FileOutputStream fileOut = new FileOutputStream(mFileExcel.getPath());
        wb.write(fileOut);
        fileOut.close();
        System.out.println("close write to file");

    }
//    private void printFileExcel() throws FileNotFoundException {
//        FileInputStream textStream;
//textStream = new FileInputStream("test.xls");
//
//DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
//Doc mydoc = new SimpleDoc(textStream, flavor, null);
//
//   PrintService[] services = PrintServiceLookup.lookupPrintServices(
//				flavor, aset);
//   PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
//
//   if(services.length == 0) {
//       if(defaultService == null) {
//             //no printer found
//
//       } else {
//            //print using default
//            DocPrintJob job = defaultService.createPrintJob();
//            job.print(mydoc, aset);
//
//       }
//
//    } else {
//
//       //built in UI for printing you may not use this
//       PrintService service = ServiceUI.printDialog(null, 200, 200, services, defaultService, flavor, aset);
//
//
//        if (service != null)
//        {
//           DocPrintJob job = service.createPrintJob();
//           job.print(mydoc, aset);
//        }
//
//    }
//    }

    private void getAllDataFromDatabase() {
        try {
            //pst = con.prepareStatement("select * from emp where UNAME='" + from + "'");
            PreparedStatement pst = con.prepareStatement("select * from Table1");
            ResultSet rs = pst.executeQuery();

            while (rs.next()) {
                PrintObject recordObject = new PrintObject(rs);
                updateValueToLayout(recordObject);
                readAndRewriteValueInExcel(recordObject);
                printFile(mFileExcel);
            }
//            if (i < 1) {
//                JOptionPane.showMessageDialog(null, "No Record Found", "Error", JOptionPane.ERROR_MESSAGE);
//            }

        } catch (Exception ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    private int getRowIndex(String data) {


        return Integer.parseInt(data.substring(1)) - 1;

    }

    private int getColumnIndex(String data) {

        char symbol = data.toUpperCase().charAt(0);
        return symbol - 'A';
    }

    private Cell getCellFromIndex(Sheet sheet, String data) {
        if (data.length() < 2) {
            return null;
        }
        int inRow = getRowIndex(data);
        int inColumn = getColumnIndex(data);
        Row row = sheet.getRow(inRow);
        Cell cell = row.getCell(inColumn);
        if (cell == null) {
            cell = row.createCell(inColumn);
        }
        return cell;
    }

    private void updateValueToLayout(PrintObject record) {
        tfAwardsValue.setText(record.getDanhHieu());
        tfNameValue.setText(record.getHoTen());
        tfClassValue.setText(record.getLop());
        tfSoCapValue.setText(record.getSoCap());
        tfSoHoSoValue.setText(record.getSoHoSo());
        tfSoQDValue.setText(record.getSoQD());
        tfDonViValue.setText(record.getDonVi());
        tfPhu1Value.setText(record.getPhu1());
        tfPhu2Value.setText(record.getPhu2());
    }

    private void updateCellValue(Cell cell, String value) {
        if (cell != null) {
            cell.setCellType(Cell.CELL_TYPE_STRING);
            cell.setCellValue(value);
        }
    }

    private void initValue() {
        
        isLoadData = false;
        pnInforLoadData.setVisible(isLoadData);
        listDataToPrint = new ArrayList<PrintObject>();
        currentSttObject = -1;
    }

    private void loadingDataToList() throws SQLException {
        listDataToPrint.clear();
        PreparedStatement pst = con.prepareStatement("select * from Table1");
        ResultSet rs = pst.executeQuery();

        while (rs.next()) {
            PrintObject recordObject = new PrintObject(rs);
            listDataToPrint.add(recordObject);
        }
    }

    private void updateViewAfterLoading() {
        currentSttObject = 0;
        isLoadData = true;
        pnInforLoadData.setVisible(isLoadData);
        lbTotalRecord.setText("/" + listDataToPrint.size());
    }

    private void updateStatusInformation() {
        tfCurrentRecord.setText("" + (currentSttObject + 1));
    }
}
